home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-12-06 | 19.1 KB | 740 lines | [TEXT/MPS ] |
- CONST
- cConvert = 3001;
- cConvertMsg = 3101;
- cICNN = 4001;
- cicl4 = 4002;
- cicl8 = 4003;
- cics = 4004;
- cics4 = 4005;
- cics8 = 4006;
-
- kFileType = 'rsrc';
- kSignature = 'RSED';
- kWindowID = 1001;
- kIconID = 1000;
- kCicnHeight = 32;
- kCicnWidth = 32;
- kIconWidth = 32;
-
- kIcl8Bytes = 1024;
- kIcl4Bytes = 512;
- kICNBytes = 256;
- kIcs8Bytes = 256;
- kIcs4Bytes = 128;
- kIcsBytes = 64;
-
- Var
- g1BitOPM : TOffScreenPixMap;
- g4BitOPM : TOffScreenPixMap;
- g8BitOPM : TOffScreenPixMap;
-
-
- {================TCicnApplication====================}
- {$S AInit}
- Procedure TCicnApplication.ICicnApplication;
- Var
- aCicnView : TCicnView;
- a1BitOPM : TOffScreenPixMap;
- a4BitOPM : TOffScreenPixMap;
- a8BitOPM : TOffScreenPixMap;
- begin
- If gDeadStripSuppression Then
- Begin
- New(aCicnView);
- End;
- SELF.IApplication(kFileType);
- SELF.fLaunchWithNewDocument := FALSE;
- {create the three off screen pixmaps}
- New(a1BitOPM);
- FailNIL(a1BitOPM);
- a1BitOPM.IOffScreenPixMap(1);
- g1BitOPM := a1BitOPM;
- New(a4BitOPM);
- FailNIL(a4BitOPM);
- a4BitOPM.IOffScreenPixMap(4);
- g4BitOPM := a4BitOPM;
- New(a8BitOPM);
- FailNIL(a8BitOPM);
- a8BitOPM.IOffScreenPixMap(8);
- g8BitOPM := a8BitOPM;
- end;
-
- {$S AInit}
- Function TCicnApplication.DoMakeDocument(itsCmdNumber : CmdNumber) :
- TDocument; OVERRIDE;
- var
- aCicnDocument : TCicnDocument;
- aWindow : TWindow;
- begin
- NEW(aCicnDocument);
- FailNIL(aCicnDocument);
- aCicnDocument.ICicnDocument;
- DoMakeDocument := aCicnDocument;
- end;
-
- {================TCicnDocument====================}
- {$S AOpen}
- Procedure TCicnDocument.ICicnDocument;
- var
- aList : TList;
- Begin
- fSaveIcon := True;
- fSaveIcl4 := True;
- fSaveIcl8 := True;
- fSaveIcs := True;
- fSaveIcs4 := True;
- fSaveIcs8 := True;
- fCicnList := NIL;
- SELF.IDocument(kFileType, kSignature, NOT kUsesDataFork,
- kUsesRsrcFork, NOT kDataOpen, kRsrcOpen);
- fSavePrintInfo := FALSE;
- aList := NewList;
- fCicnList := aList;
- SELF.fRsrcPerm := fsRdWrPerm;
- {$IFC qDebug}
- fCicnList.SetEltType('TCicn');
- {$ENDC}
- end;
-
- {$S AOpen}
- Procedure TCicnDocument.DoMakeViews(forPrinting : boolean); OVERRIDE;
- var
- aWindow : TWindow;
- aCicnView : TCicnView;
- aHandler : TStdPrintHandler;
- minSize, maxSize : Point;
- begin
- aWIndow := NewTemplateWindow(kWIndowID, SELF);
- SetPt(minSize, 64, 64);
- SetPt(maxSize, 303, 480);
- aWIndow.SetResizeLimits(minSize, maxSize);
- aCicnView := TCicnView(aWindow.FindSubView('Cicn'));
- fCicnView := aCicnView;
- NEW(aHandler);
- FailNIL(aHandler);
- aHandler.IStdPrintHandler(SELF,aCicnView, NOT kSquareDots, kFixedSize,
- NOT kFixedSize);
- End;
-
- {$S ARes}
- Procedure TCicnDocument.DoSetupMenus; OVERRIDE;
- Begin
- INHERITED DoSetupMenus;
- Enable(cConvert, SELF.fCicnList.GetSize > 0);
- EnableCheck(cICNN, SELF.fCicnList.GetSize > 0, SELF.fSaveIcon);
- EnableCheck(cicl4, SELF.fCicnList.GetSize > 0, SELF.fSaveicl4);
- EnableCheck(cicl8, SELF.fCicnList.GetSize > 0, SELF.fSaveicl8);
- EnableCheck(cics, SELF.fCicnList.GetSize > 0, SELF.fSaveics);
- EnableCheck(cics4, SELF.fCicnList.GetSize > 0, SELF.fSaveics4);
- EnableCheck(cics8, SELF.fCicnList.GetSize > 0, SELF.fSaveics8);
- End;
-
- {$S ASelCommand}
- Function TCicnDocument.DoMenuCommand(aCmdNumber : CmdNumber) : TCommand; OVERRIDE;
- Begin
- Case aCmdNumber Of
- cConvert :
- SELF.DoWrite(SELF.fRsrcRefNum, FALSE);
- cICNN :
- SELF.fSaveIcon := Not(SELF.fSaveIcon);
- cicl4 :
- SELF.fSaveIcl4 := Not(Self.fSaveIcl4);
- cicl8 :
- SELF.fSaveIcl8 := Not(Self.fSaveIcl8);
- cics :
- SELF.fSaveIcs := Not(Self.fSaveIcs);
- cics4 :
- SELF.fSaveIcs4 := Not(Self.fSaveIcs4);
- cics8 :
- SELF.fSaveIcs8 := Not(Self.fSaveIcs8);
- Otherwise
- DoMenuCommand := INHERITED DoMenuCommand(aCmdNUmber);
- End; {Case}
- End;
-
- {$S ARes}
- Procedure TCicnDocument.ForEachCicnDo(Procedure Something(aCicn : TCicn));
- Begin
- fCicnList.Each(Something);
- End;
-
- {$S AWriteFile}
- Procedure TCicnDocument.DoNeedDiskSpace(VAR dataForkBytes,
- rsrcForkBytes : LongInt); OVERRIDE;
- Var
- numOfCicns, bytesPerRsrc : LongInt;
- Begin
- INHERITED DoNeedDiskSpace(dataForkBytes, rsrcForkBytes);
- numOfCicns := fCicnList.GetSize;
- bytesPerRsrc := 0;
- If SELF.fSaveIcon Then
- bytesPerRsrc := bytesPerRsrc + kICNBytes;
- If SELF.fSaveIcl4 Then
- bytesPerRsrc := bytesPerRsrc + kIcl4Bytes;
- If SELF.fSaveIcl8 Then
- bytesPerRsrc := bytesPerRsrc + kIcl8Bytes;
- If SELF.fSaveIcs Then
- bytesPerRsrc := bytesPerRsrc + kIcsBytes;
- If SELF.fSaveIcs4 Then
- bytesPerRsrc := bytesPerRsrc + kIcs4Bytes;
- If SELF.fSaveIcs8 Then
- bytesPerRsrc := bytesPerRsrc + kIcs8Bytes;
- bytesPerRsrc := bytesPerRsrc + kRsrcOverhead;
- rsrcForkBytes := rsrcForkBytes + numOfCicns * bytesPerRsrc + 6 * kRsrcTypeOverhead;
- End;
-
- {$S AReadFile}
- Procedure TCicnDocument.DoRead(aRefNum : integer; rsrcExists,
- forPrinting : Boolean); OVERRIDE;
- var
- numberOfCicns : Integer;
- aCicn : TCicn;
- index : Integer;
- Begin
- INHERITED DoRead(aRefNum, rsrcExists, forPrinting);
- numberOfCicns := Count1Resources('cicn');
- FailResError;
- For index := 1 to numberOfCicns do
- Begin
- New(aCicn);
- FailNil(aCicn);
- aCicn.ICicn(SELF);
- aCicn.ReadCicn(index);
- SELF.AddCicnLast(aCicn);
- End;
- End;
-
- {$S AWriteFile}
- Procedure TCicnDocument.DoWrite(aRefNum : integer; makingCopy : Boolean); OVERRIDE;
- Var
- hPB : HParamBlockRec;
- freeBlks, blkSize, neededBlks, usedBlks : LongInt;
- dataBytes, rsrcBytes : LongInt;
- err : OSErr;
- name: Str255;
- volRefnum: INTEGER;
-
- Procedure Local(aCicn : TCicn);
- Begin
- aCicn.fCicnHandle := GetCIcon(aCicn.fId);
- aCicn.WriteResources(aRefNum);
- DisposCIcon(aCicn.fCicnHandle);
- End;
-
- Begin
- {Get information about the volume saving to}
- WITH hPB DO
- BEGIN
- ioNamePtr := NIL;
- ioVRefnum := SELF.fVolRefnum;
- ioVolIndex := 0;
- END;
- FailOSerr(PBHGetVInfo(@hPB, FALSE));
-
- {on HFS ioVFrBlk is an unsigned INTEGER; on MFS it is
- limited to a positive signed INTEGER}
- freeBlks := BAND(hPB.ioVFrBlk, $0000FFFF) - 1; {-1 for some slop -- don't try to fill up
- the disk completely}
-
- {compute size needed to save document}
- blkSize := hPB.ioVAlBlkSiz;
-
- dataBytes := 0;
- rsrcBytes := 0;
- DoNeedDiskSpace(dataBytes, rsrcBytes);
- neededBlks := NumBlocks(rsrcBytes, blkSize) + NumBlocks(dataBytes, blkSize);
-
- IF freeBlks >= neededBlks THEN
- Begin
- INHERITED DoWrite(aRefNum, makingCopy);
- SELF.ForEachCicnDo(Local);
- End
- Else
- Failure(dskFulErr, 0);
- {$IFC qDebug}
- err := GetFileInfo(name, volRefnum, hPB);
- IF err = noErr THEN
- BEGIN
- usedBlks := NumBlocks(hPB.ioFlRPyLen, blkSize) + NumBlocks(hPB.ioFlPyLen, blkSize);
- IF usedBlks <> neededBlks THEN
- BEGIN
- Writeln('In TDocument.Save: DoNeedDiskSpace estimated disk space incorrectly.');
- Writeln('estimated # disk blocks = ', neededBlks: 1);
- Writeln(' actual # disk blocks = ', usedBlks: 1);
- END;
- END;
- {$ENDC}
- End;
-
- {$S AClose}
- Procedure TCicnDocument.Free; OVERRIDE;
- begin
- If fCicnList <> NIL then
- fCicnList.FreeList;
- INHERITED Free;
- end;
-
- {$S AReadFile}
- Procedure TCicnDocument.FreeData; OVERRIDE;
- Begin
- fCicnList.FreeAll; {frees TCicn objects only}
- End;
-
- {$S ASelCommand}
- Procedure TCicnDocument.AddCicnLast(aCicn : TCicn);
- Begin
- fCicnList.InsertLast(aCicn);
- End;
-
- {$S ASelCommand}
- Procedure TCicnDocument.DeleteCicn(aCicn : TCicn);
- Begin
- fCicnList.Delete(aCicn);
- End;
-
- {$S ASelCommand}
- Function TCicnDocument.CicnAt(theIndex : Integer) : TCicn;
- Begin
- CicnAt := TCicn(fCicnList.At(theIndex));
- End;
-
- {$IFC qDebug}
- Procedure TCicnDocument.Fields(Procedure DoToField(
- fieldName : Str255; fieldAddr : Ptr; fieldType :
- integer)); OVERRIDE;
- Begin
- DoToField('TCicnDocument', NIL, bClass);
- DoToField('fCicnList', @fCicnList, bObject);
- DoToField('fCicnView', @fCicnView, bObject);
- DoToField('fSaveIcon', @fSaveIcon, bBoolean);
- DoToField('fSaveIcl4', @fSaveIcl4, bBoolean);
- DoToField('fSaveIcl8', @fSaveIcl8, bBoolean);
- DoToField('fSaveIcs', @fSaveIcs, bBoolean);
- DoToField('fSaveIcs4', @fSaveIcs4, bBoolean);
- DoToField('fSaveIcs8', @fSaveIcs8, bBoolean);
- INHERITED Fields(DoToField);
- End;
- {$ENDC}
-
- {============================= TCicnView ================================}
- {$S ARes}
- Procedure TCicnView.IRes(itsDocument : TDocument; itsSuperView : TView;
- Var itsParams : Ptr); OVERRIDE;
- Var
- numOfCicns, numOfRows : Integer;
- Begin
- INHERITED Ires(itsDocument, itsSUperView, itsParams);
- fCicnDocument := TCicnDocument(itsDocument);
- numOfCicns := SELF.fCicnDocument.fCicnList.GetSize;
- If numOfCicns > 0 Then
- Begin
- numOfRows := (numOfCicns + 7) DIV 8 - 1;
- SELF.InsRowLast(numOfRows, 36);
- End;
- End;
-
- {$S ARes}
- Procedure TCicnView.DrawCell(aCell : GridCell; aQDRect : Rect); OVERRIDE;
- Var
- theCicn : Integer;
- aCicn : TCicn;
- Begin
- theCicn := (aCell.v - 1) * 8 + aCell.h;
- if theCicn <= SELF.fCicnDocument.fCicnList.GetSize Then
- Begin
- aCicn := SELF.fCicnDocument.CicnAt(theCicn);
- aCicn.DrawCicn(aQDRect);
- End;
- End;
-
- {$IFC qDebug}
- Procedure TCicnView.Fields(Procedure DoToField(
- fieldName : Str255; fieldAddr : Ptr; fieldType :
- integer)); OVERRIDE;
- Begin
- DoToField('TCicnView', NIL, bClass);
- DoToField('fCicnDocument', @fCicnDocument, bObject);
- INHERITED Fields(DoToField);
- End;
- {$ENDC}
-
- {============================= TCicn =============================}
- {$S ASelCommand}
- Procedure TCicn.ICicn(aCicnDocument : TCicnDocument);
- Begin
- SELF.fId := 128;
- SELF.fName := '';
- SELF.fCicnHandle := NIL;
- SELF.fCicnDocument := aCicnDocument;
- End;
-
- {$S ARes}
- Procedure TCicn.DrawCicn(theRect : Rect);
- Type
- BitMapPtr = ^BitMap;
- Var
- srcRect : Rect;
- oldPort : CGrafPtr;
- oldDevice : GDHandle;
- theCicn : CIconHandle;
- Begin
- theCicn := GetCIcon(SELF.fId);
- If gPrinting Then
- Begin {since PlotCIcon does not use QD picture calls, have to copybits from opm}
- GetPort(GrafPtr(oldPort));
- oldDevice := GetGDevice;
- SetGDevice(g8BitOPM.fGDevice);
- SetPort(GrafPtr(g8BitOPM.fCGrafPtr));
- srcRect := g8BitOPM.fCGrafPtr^.portPixMap^^.bounds;
- EraseRect(srcRect);
- PlotCIcon(srcRect, theCicn);
- SetPort(GrafPtr(oldPort));
- SetGDevice(oldDevice);
- RGBForeColor(gRGBBlack);
- RGBBackColor(gRGBWhite);
- CopyBits(BitMapPtr(g8BitOPM.fCGrafPtr^.portPixMap^)^, GrafPtr(oldPort)^.portBits ,
- g8BitOPM.fCGrafPtr^.portPixMap^^.bounds, theRect, srcCopy, NIL);
- End
- Else
- PlotCIcon(theRect, theCicn);
- DisposCIcon(theCicn);
- End;
-
- {$S AWrite}
- Function TCicn.ExtractRsrc(theDepth : Integer; halfSize : Boolean) : Handle;
- Var
- oldPort : CGrafPtr;
- oldDevice : GDHandle;
- theRsrc : Handle;
- theCicn : CIconHandle;
- theRect : Rect;
- theOPM : TOffScreenPixMap;
- cntr : Integer;
- bytesPerRow : LongInt;
- Begin
- GetPort(GrafPtr(oldPort));
- oldDevice := GetGDevice;
- theCicn := SELF.fCicnHandle;
- Case theDepth of
- 1: theOPM := g1BitOPM;
- 4: theOPM := g4BitOPM;
- 8: theOPM := g8BitOPM;
- Otherwise;
- End;
- If halfSize Then
- theRsrc := NewPermHandle(theOPM.fSize DIV 4)
- Else
- theRsrc := NewPermHandle(theOPM.fSize);
- FailNil(theRsrc);
- SetGDevice(theOPM.fGDevice);
- SetPort(GrafPtr(theOPM.fCGrafPtr));
- theRect := theOPM.fCGrafPtr^.portPixMap^^.bounds;
- If halfSize Then
- Begin
- theRect.bottom := theRect.bottom DIV 2;
- theRect.right := theRect.right DIV 2;
- End;
- EraseRect(theRect);
- PlotCIcon(theRect, theCicn);
- If halfSize Then
- Begin
- bytesPerRow := (theOPM.fCGrafPtr^.portPixMap^^.rowBytes - $8000) DIV 2;
- for Cntr := 1 to (theRect.bottom - theRect.top) Do
- BlockMove(Pointer(Ord(theOPM.fBits) + (cntr - 1) * bytesPerRow * 2),
- Pointer(Ord(theRsrc^) + (cntr - 1) * bytesPerRow), bytesPerRow);
- End
- Else
- BlockMove(theOPM.fBits, theRsrc^, theOPM.fSize);
- ExtractRsrc := theRsrc;
- SetGDevice(oldDevice);
- SetPort(GrafPtr(oldPort));
- End;
-
- {$S AWrite}
- Function TCicn.ExtractMask(halfSize : Boolean) : Handle;
- Type
- BitMapPtr = ^BitMap;
- Var
- oldPort : CGrafPtr;
- oldDevice : GDHandle;
- theRect : Rect;
- theRsrc : Handle;
- cntr : Integer;
- bytesPerRow : LongInt;
- Begin
- GetPort(GrafPtr(oldPort));
- oldDevice := GetGDevice;
- If halfSize Then
- theRsrc := NewPermHandle(g1BitOPM.fSize DIV 4)
- Else
- theRsrc := NewPermHandle(g1BitOPM.fSize);
- FailNIL(theRsrc);
- SetGDevice(g1BitOPM.fGDevice);
- SetPort(GrafPtr(g1BitOPM.fCGrafPtr));
- RGBForeColor(gRGBBlack);
- RGBBackColor(gRGBWhite);
- theRect := g1BitOPM.fCGrafPtr^.portPixMap^^.bounds;
- If halfSize Then
- Begin
- theRect.bottom := theRect.bottom DIV 2;
- theRect.right := theRect.right DIV 2;
- End;
- EraseRect(theRect);
- CopyBits(SELF.fCicnHandle^^.iconMask, BitMapPtr(g1BitOPM.fCGrafPtr^.portPixMap^)^,
- Self.fCicnHandle^^.iconMask.bounds, theRect, srcCopy, NIL);
- If halfSize Then
- Begin
- bytesPerRow := (g1BitOPM.fCGrafPtr^.portPixMap^^.rowBytes - $8000) DIV 2;
- For cntr := 1 to (theRect.bottom - theRect.top) Do
- BlockMove(Pointer(Ord(g1BitOPM.fBits) + (cntr - 1) * bytesPerRow * 2),
- Pointer(Ord(theRsrc^) + (cntr - 1) * bytesPerRow), bytesPerRow);
- End
- Else
- BlockMove(g1BitOPM.fBits, theRsrc^, g1BitOPM.fSize);
- ExtractMask := theRsrc;
- SetGDevice(oldDevice);
- SetPort(GrafPtr(oldPort));
- End;
-
- {$S AWriteFile}
- Procedure TCicn.RemoveOldResources(id : Integer);
-
- Procedure RemoveThem(theType : ResType);
- Var
- theResHandle : Handle;
- Begin
- theResHandle := Get1Resource(theType, id);
- While theResHandle <> NIL Do
- Begin
- RmveResource(theResHandle);
- FailResError;
- theResHandle := Get1Resource(theType, id);
- End;
- End;
-
- Begin
- SetResLoad(False);
- If SELF.fCicnDocument.fSaveIcon Then
- RemoveThem('ICN#');
- If SELF.fCicnDocument.fSaveIcs Then
- RemoveThem('ics#');
- If SELF.fCicnDocument.fSaveIcl4 Then
- RemoveThem('icl4');
- If SELF.fCicnDocument.fSaveIcs4 Then
- RemoveThem('ics4');
- If SELF.fCicnDocument.fSaveIcl8 Then
- RemoveThem('icl8');
- If SELF.fCicnDocument.fSaveIcs8 Then
- RemoveThem('ics8');
- SetResLoad(True);
- End;
-
- {$S AWriteFile}
- Procedure TCicn.WriteResources(aRefNum : integer);
- Var
- theRes, theMask : Handle;
-
- Procedure AddNewRes(typeOfRes : ResType);
- Var
- resName : Str255;
- Begin
- resName := SELF.fName;
- AddResource(theRes, typeOfRes, SELF.fId, resName);
- FailResError;
- WriteResource(theRes);
- FailResError;
- ReleaseResource(theRes); {don't need the ICON in memory since it has been written out}
- FailResError;
- End;
-
- Begin
- SELF.RemoveOldResources(SELF.fId);
- If SELF.fCicnDocument.fSaveIcon Then
- Begin
- theRes := SELF.ExtractRsrc(1, False);
- theMask := SELF.ExtractMask(False);
- FailOSErr(HandAndHand(theMask, theRes));
- AddNewRes('ICN#');
- DisPosIfHandle(theMask);
- End;
- If SELF.fCicnDocument.fSaveIcs Then
- Begin
- theRes := SELF.ExtractRsrc(1, True);
- theMask := SELF.ExtractMask(True);
- FailOSErr(HandAndHand(theMask, theRes));
- AddNewRes('ics#');
- DisPosIfHandle(theMask);
- End;
- If SELF.fCicnDocument.fSaveIcl4 Then
- Begin
- theRes := SELF.ExtractRsrc(4, False);
- AddNewRes('icl4');
- End;
- If SELF.fCicnDocument.fSaveIcs4 Then
- Begin
- theRes := SELF.ExtractRsrc(4, True);
- AddNewRes('ics4');
- End;
- If SELF.fCicnDocument.fSaveIcl8 Then
- Begin
- theRes := SELF.ExtractRsrc(8, False);
- AddNewRes('icl8');
- End;
- If SELF.fCicnDocument.fSaveIcs8 Then
- Begin
- theRes := SELF.ExtractRsrc(8, True);
- AddNewRes('ics8');
- End;
- End;
-
- {$S AWriteFile}
- Function TCicn.ReturnBytes : LongInt;
- Begin
- {$PUSH} {$H-}
- ReturnBytes := 1024 + 512 + 256 + 12;
- {$POP}
- End;
-
- {$S ARes}
- Procedure TCicn.Free; OVERRIDE;
- Begin
- SELF.fId := 0;
- SELF.fName := '';
- SELF.fCicnHandle := NIL;
- INHERITED Free;
- End;
-
- {$S AReadFile}
- Procedure TCicn.ReadCicn(index : Integer);
- Var
- theId : Integer;
- theType : ResType;
- theName : Str255;
- theCicnHandle : Handle;
- Begin
- SetResLoad(FALSE); {only load in the Handle to the resource for now}
- theCicnHandle := Get1IndResource('cicn', index);
- GetResInfo(theCicnHandle, theId, theType, theName);
- SELF.fId := theId;
- SELF.fName := theName;
- SetResLoad(TRUE);
- End;
-
- {$S ASelCommand}
- Function TCicn.ReturnFrame : Rect;
- Begin
- End;
-
- {$IFC qDebug}
- Procedure TCicn.Fields(Procedure DoToField(fieldName : Str255;
- fieldAddr : Ptr; fieldType : Integer)); OVERRIDE;
- Begin
- DoToField('TCicn', NIL, bClass);
- DoToField('fId', @fId, bInteger);
- DoToField('fName', @fName, bString);
- DoToField('fCicnHandle', @fCicnHandle, bHandle);
- INHERITED Fields(DoToField);
- End;
- {$ENDC}
-
- {============================= TCicn =============================}
- Procedure TOffScreenPixMap.IOffScreenPixMap(theDepth : Integer);
- Var
- bRect : Rect;
- aCGrafPtr : CGrafPtr;
- theRowBytes, size : Longint;
- cntr : Integer;
- bits : Ptr;
- theDevice, oldDevice : GDHandle;
- Begin
- oldDevice := GetGDevice;
- SELF.fCGrafPtr := NIL;
- SELF.fBits := NIL;
- SELF.fGDevice := NIL;
- SELF.fSize := 0;
- SetRect(bRect, 0, 0, 32, 32);
- theRowBytes := (((theDepth * 32) + 15) DIV 16) * 2;
- size := LongInt(32 * theRowBytes);
- SELF.fSize := size;
- bits := NewPermPtr(size);
- FailNil(bits);
- SELF.fBits := bits;
- {create a graphics device}
- theDevice := NewGDevice(0, -1);
- FailNIL(theDevice);
- SELF.fGDevice := theDevice;
- LockHandleHigh(Handle(SELF.fGDevice));
- With SELF.fGDevice^^ Do
- Begin
- gdId := 0;
- gdType := 0; {CLUT device}
- {set up color table}
- LockHandleHigh(Handle(gdPMap));
- DisposCTable(gdPMap^^.pmTable);
- gdPMap^^.pmTable := GetCTable(theDepth);
- FailNIL(gdPMap^^.pmTable);
- FailOSErr(HandToHand(Handle(gdPMap^^.pmTable)));
- {$PUSH} {$R-}
- For cntr := 0 to gdPMap^^.pmTable^^.ctSize Do
- gdPMap^^.pmTable^^.ctTable[cntr].value := cntr;
- {$POP}
- gdPMap^^.pmTable^^.ctFlags := BAnd(gdPMap^^.pmTable^^.ctFlags, $7FFF);
- gdPMap^^.pmTable^^.ctSeed := GetCTSeed;
- {make inverse table}
- MakeITable(gdPMap^^.pmTable, gdITable, 3);
- FailOSErr(QDError);
- gdResPref := 3;
- gdSearchProc := NIL;
- gdCompProc := NIL;
- SetDeviceAttribute(theDevice, gdDevType , True);
- SetDeviceAttribute(theDevice, ramInit, True);
- SetDeviceAttribute(theDevice, noDriver, True);
- SetDeviceAttribute(theDevice, screenActive, True);
- With gdPMap^^ do
- Begin
- baseAddr := bits;
- rowBytes := theRowBytes + $8000; {remember to be a PixMap}
- bounds := bRect;
- pixelSize := theDepth;
- cmpCount := 1;
- cmpSize := theDepth;
- End;
- HUnlock(Handle(gdPMap));
- gdRect := bRect;
- End;
- HUnlock(Handle(theDevice));
- SetGDevice(theDevice);
- aCGrafPtr := CGrafPtr(NewPermPtr(SizeOf(cGrafPort)));
- FailNIL(aCGrafPtr);
- SELF.fCGrafPtr := aCGrafPtr;
- OpenCPort(aCGrafPtr);
- SetGDevice(oldDevice);
- End;
-
- {$S Res}
- Procedure TOffScreenPixMap.Free; OVERRIDE;
- Begin
- DisPosIfPtr(SELF.fBits);
- If SELF.fCGrafPtr <> NIL Then
- Begin
- CloseCPort(SELF.fCGrafPtr);
- DisposPtr(Ptr(SELF.fCGrafPtr));
- End;
- If SELF.fGDevice <> NIL Then
- DisposGDevice(SELF.fGDevice);
- INHERITED Free;
- End;
-
- {$IFC qDebug}
- Procedure TOffScreenPixMap.Fields(Procedure DoToField(fieldName : Str255;
- fieldAddr : Ptr; fieldType : Integer)); OVERRIDE;
- Begin
- DoToField('TOffScreenPixMap', NIL, bClass);
- DoToField('fCGrafPtr', @fCGrafPtr, bPointer);
- DoToField('fBits', @fBits, bPointer);
- DoToField('fGDevice', @fGDevice, bHandle);
- DoToField('fSize', @fSize, bLongInt);
- INHERITED Fields(DoToField);
- End;
- {$ENDC}
-